package com.newegg.research.tfidfAnalyzer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Token的描述类
 * @author Jin.H.Gao@NeweggLab
 */
public class Token
{
	Map<Category, Integer> count_in_all_categories = new HashMap<Category, Integer>();

	int sumCount = 0;

	String content = "undefined";

	public int getCountInCategory(Category c)
	{
		if (count_in_all_categories.containsKey(c))
		{
			return count_in_all_categories.get(c);
		} else
		{
			return 0;
		}
	}

	List<Category> getAllRelatedCategory()
	{
		Set<Category> set = count_in_all_categories.keySet();
		return new ArrayList<Category>(set);
	}

	public String toString()
	{
		return content;
	}

	public int hashCode()
	{
		return content.hashCode();
	}

	public boolean equals(Object obj)
	{
		if (obj == null)
			return false;
		else if (!(obj instanceof Token))
			return false;
		else if (((Token) obj).getContent().equals(content))
			return true;
		else
			return false;
	}

	Token(String str)
	{
		setContent(str);
	}

	void increaseCount(Category category)
	{
		if (count_in_all_categories.containsKey(category))
		{
			int i = count_in_all_categories.get(category);
			count_in_all_categories.put(category, ++i);
		} else
		{
			count_in_all_categories.put(category, 1);
		}
		sumCoundIncrease();
	}

	String getContent()
	{
		return content;
	}

	void setContent(String str)
	{
		content = str;
	}

	public int getSumCount()
	{
		return sumCount;
	}

	void sumCoundIncrease()
	{
		sumCount++;
	}
}
